Skip to content

Add simple regression summaries and Student t random variable#21

Merged
HubertRonald merged 7 commits into
masterfrom
feature/v0.8.0-simple-regression
Jun 10, 2026
Merged

Add simple regression summaries and Student t random variable#21
HubertRonald merged 7 commits into
masterfrom
feature/v0.8.0-simple-regression

Conversation

@HubertRonald

Copy link
Copy Markdown
Owner

Summary

This PR prepares LuaSF for v0.8.0 by adding a Student's t random variable generator and formula-based simple linear regression summaries.

It builds on the modular source layout, bivariate statistics, shape statistics, and probability helpers introduced in previous releases.

What changed

Added Student's t random variable generator

Added:

stats.studentTVA(df)
stats.student_t(df)
stats.t_student(df)

The Student's t random variable is generated using the standard relationship:

T = Z / sqrt(V / df)

where Z is an approximately standard normal random variable and V is a chi-square random variable with df degrees of freedom.

Added simple regression module

Added:

src/luasf/regression.lua

The module exposes:

stats.simple_linear_regression(x, y)
stats.predict(model, x)
stats.fitted_values(model)
stats.residuals(model)

Regression summary output

simple_linear_regression(x, y) returns a formula-based regression summary including:

  • Slope
  • Intercept
  • R
  • R squared
  • Adjusted R squared
  • SSE
  • SSR
  • SST
  • MSE
  • RMSE
  • Residual standard error
  • Standard error for slope
  • Standard error for intercept
  • T statistic for slope
  • T statistic for intercept
  • Fitted values
  • Residuals
  • ANOVA-style summary without p-values

Added tests

Added:

spec/test_student_t.lua
spec/test_regression.lua

The tests cover:

  • Student's t random variable aliases
  • Degrees of freedom validation
  • Perfect simple linear regression
  • Regression with intercept
  • Prediction helper
  • Fitted values helper
  • Residuals helper
  • Regression summary fields
  • Input validation

Added examples

Added:

examples/student_t_distribution.lua
examples/simple_linear_regression.lua

Added LuaRocks rockspec

Added:

rockspec/luasf-0.8.0-1.rockspec

Updated workflows

Updated GitHub Actions workflows to include:

lua spec/test_student_t.lua
lua spec/test_regression.lua
lua examples/student_t_distribution.lua
lua examples/simple_linear_regression.lua

The LuaRocks publishing workflow now defaults to:

rockspec/luasf-0.8.0-1.rockspec

Updated documentation

Updated:

README.md
docs/api.md
CHANGELOG.md
CONTRIBUTING.md

Compatibility notes

This PR does not remove or rename existing public functions.

Existing usage remains supported:

local stats = require("luasf")
local stats = require("LuaSF")
local stats = require("LuaStat")

Legacy LuaSF names remain available.

Testing

Tested locally with:

lua spec/test_stats.lua
lua spec/test_distributions.lua
lua spec/test_sampling.lua
lua spec/test_bivariate.lua
lua spec/test_shape.lua
lua spec/test_probability.lua
lua spec/test_student_t.lua
lua spec/test_regression.lua

Examples can be run with:

lua examples/dice_simulation.lua
lua examples/normal_quality_control.lua
lua examples/gamma_distribution.lua
lua examples/weighted_loot_drop.lua
lua examples/monte_carlo_pi.lua
lua examples/poisson_arrivals.lua
lua examples/binomial_coin_flips.lua
lua examples/bootstrap_mean.lua
lua examples/covariance_correlation.lua
lua examples/skewness_kurtosis.lua
lua examples/probability_helpers.lua
lua examples/student_t_distribution.lua
lua examples/simple_linear_regression.lua

Release target

This PR prepares LuaSF for:

v0.8.0 - Simple Regression Summaries and Student's t Random Variable

Scope note

LuaSF now includes formula-based simple regression summaries, but it does not compute p-values, confidence intervals, critical values, multiple regression, non-linear regression, or machine learning workflows.

The goal remains to keep LuaSF lightweight, pure Lua, readable, and useful for statistics, probability, simulation, and teaching.

@HubertRonald HubertRonald merged commit 9bde7f4 into master Jun 10, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant